// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
        playLabel:{
            default:null,
            type:cc.Label
        },
        pasueLabel:{
            default:null,
            type:cc.Label
        },
        stateLabel:{
            default:null,
            type:cc.Label
        },
        animation:{
            default:null,
            type:cc.Animation
        }
    },
    onEnable:function(){
        var animation=this.animation;

        animation.on('play',this.onPlay,this);

        animation.on('stop',this.onStop,this);

        animation.on("lastframe",this.onLasFrame,this);

        animation.on('finished',this.onFinished,this);

        animation.on('pause',this.onPause,this);

        animation.on('resume',this.onResume,this);
    },

    onPlayButtonClicked:function(){
        if(this.playLabel.string==='play'){
            this.playLabel.string='stop';

            this.animation.play('Linear');
        }
        else {
            thisl.playLabel.string='play';

            this.animation.stop('Linear');
        }
    },

    onPauseButonClicked:function(){
        if(this.pasueLabel.string==='pause'){
            this.pasueLabel.string='resume';

            this.animation.pause('Linear');
        }
        else {
            this.pasueLabel.string='pause';

            this.animation.resume('Linear');
        }
    },
    // LIFE-CYCLE CALLBACKS:
    onPlay:function(){
        cc.log("onPlay");

        this.stateLabel.string="onPlay";
    },
    onStop:function(){
        cc.log("onStop");

        this.stateLabel.string='onStop';

        this.playLabel.string='play'
    },

    onLasFrame:function(){
        cc.log('onLastFrame');

        this.stateLabel.string='onLastFrame';
    },

    onFinished:function(){
        cc.log('onFinished');

        this.stateLabel.string='onFinished';

    },

    onPause:function(){
        cc.log('onPause');

        this.stateLabel.string='onPause';

    },

    onResume:function(){
        cc.log('onResume');

        this.stateLabel.string="onResume";
    },
    // onLoad () {},

    start () {

    },

    // update (dt) {},
});
